﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang_NewApp.DBAccess;

namespace QuanLyBanHang_NewApp.DAL
{
    public class NhaCungCapDAL
    {
        dbConnection conn;

        public NhaCungCapDAL()
        {
            conn = new dbConnection();
        }

        public DataTable selectNCC(string ten)
        {
            string query = "select * from NHACUNGCAP where TenNCC like '%'+@ten+'%'";
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@ten", ten);
            return conn.execSelectQuery(query, p);
        }

        public bool insertNCC(string ten, string dc, string sodt)
        {
            string query = "insert into NHACUNGCAP values(@ten,@diachi,@sodt)";

            SqlParameter[] p = new SqlParameter[3];
            p[0] = new SqlParameter("@ten", ten);            
            p[1] = new SqlParameter("@diachi", dc);
            p[2] = new SqlParameter("@sodt", sodt);                        
            
            return conn.execInsertQuery(query, p);
        }

        public bool updateNCC(long mancc, string ten, string dc, string sodt)
        {
            string query = "update NHACUNGCAP set TenNCC=@ten, DiaChi=@diachi, SoDT=@sodt where MaNCC=@mancc";

            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@ten", ten);
            p[1] = new SqlParameter("@diachi", dc);
            p[2] = new SqlParameter("@sodt", sodt);
            p[3] = new SqlParameter("@mancc", mancc);

            return conn.execInsertQuery(query, p);
        }

        public bool deleteNCC(long id)
        {
            string query = "delete from NHACUNGCAP where MaNCC =@mancc";
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@mancc", id);
            return conn.execDeleteQuery(query, p);
        }

        public DataTable selectByID(long mancc)
        {
            string query = "select * from NHACUNGCAP where MaNCC =@mancc";
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@mancc", mancc);
            return conn.execSelectQuery(query, p);
        }
        
    }
}
